#!/bin/sh
#
# Run a simple backup
#  to two tapes where the maximum tape file size is set to 1M
#  Note, this test simulates the tape filling and writing to
#   the next tape.
#
TestName="two-volume-changer"
JobName=twovolchanger
. scripts/functions

require_tape_drive
require_autochanger

scripts/cleanup
scripts/copy-2tape-confs
scripts/prepare-two-tapes

outf="tmp/sed_tmp"
echo "s%# Maximum File Size%  Maximum File Size%g" >${outf}
cp ${cwd}/bin/susan-sd.conf ${cwd}/tmp/1
sed -f ${outf} ${cwd}/tmp/1 >${cwd}/bin/susan-sd.conf

change_jobname $JobName

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

# Write out bconsole commands
cat <<END_OF_DATA >tmp/bconcmds
@$out /dev/null
messages
@$out tmp/log1.out
label storage=tape volume=TestVolume001 slot=$SLOT1 pool=Default drive=$DRIVE1
label storage=tape volume=TestVolume002 slot=$SLOT2 pool=Default drive=$DRIVE1
update Volume=TestVolume002 MaxVolBytes=3000000 pool=Default drive=$DRIVE1
sql
select * from Storage;
select VolumeName,InChanger,Slot,StorageId from Media;

@#setdebug level=1000 client=$CLIENT
setdebug level=150 storage=tape
run job=$JobName yes
wait
sql
select * from Storage;
select VolumeName,InChanger,Slot,StorageId from Media;

messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=tape
stop_susan

$scripts/${AUTOCHANGER_SCRIPT} ${AUTOCHANGER} unload $SLOT2 ${TAPE_DRIVE} 0

cat <<END_OF_DATA >tmp/bconcmds
@$out /dev/null
messages
@#
@# now do a restore
@#
@$out tmp/log2.out
restore where=${cwd}/tmp/susan-restores select all storage=tape done
yes
wait
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=tape
stop_susan

check_two_logs
check_restore_diff
end_test
